<template>
    <div class="app-wrapper">
        <el-steps :active="active" simple finish-status="success">
            <el-step title="1 基本信息" icon="el-icon-edit" description="请录入活动基本信息"></el-step>
            <el-step title="2 人员信息" icon="el-icon-upload" description="请录入活动人员信息"></el-step>
            <el-step title="3 审核信息" icon="el-icon-picture" description="请录入活动审核信息"></el-step>
        </el-steps>
        <el-form v-loading.fullscreen.lock="loading" element-loading-text="拼命提交中" element-loading-spinner="el-icon-loading" ref="form" :model="form" label-width="100px">
            <el-card v-show="showCurrent(0)">
                <el-form-item label="活动名称">
                    <el-input v-model="form.name" style="width: 300px;"></el-input>
                </el-form-item>
                <el-form-item label="活动区域">
                    <el-select v-model="form.region" placeholder="请选择活动区域" style="width: 300px;">
                        <el-option label="区域一" value="shanghai"></el-option>
                        <el-option label="区域二" value="beijing"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="活动时间">
                    <el-date-picker style="width: 300px;" v-model="form.range" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
                    </el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="next">下一步</el-button>
                </el-form-item>
            </el-card>
            <el-card v-show="showCurrent(1)">
                <el-form-item label="即时配送">
                    <el-switch v-model="form.delivery"></el-switch>
                </el-form-item>
                <el-form-item label="活动性质">
                    <el-checkbox-group v-model="form.type">
                        <el-checkbox label="美食/餐厅线上活动" name="type"></el-checkbox>
                        <el-checkbox label="地推活动" name="type"></el-checkbox>
                        <el-checkbox label="线下主题活动" name="type"></el-checkbox>
                        <el-checkbox label="单纯品牌曝光" name="type"></el-checkbox>
                    </el-checkbox-group>
                </el-form-item>
                <el-form-item label="特殊资源">
                    <el-radio-group v-model="form.resource">
                        <el-radio label="线上品牌商赞助"></el-radio>
                        <el-radio label="线下场地免费"></el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item>
                    <el-button type="default" @click="prev">上一步</el-button>
                    <el-button type="primary" @click="next">下一步</el-button>
                </el-form-item>
            </el-card>
            <el-card v-show="showCurrent(2)">
                <el-form-item label="活动描述">
                    <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 6}" v-model="form.desc"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="default" @click="prev">上一步</el-button>
                    <el-button type="success" @click="onSubmit">完成提交</el-button>
                </el-form-item>
            </el-card>
        </el-form>
    </div>
</template>
<script>
import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      loading: false,
      active: 0,
      form: {
        name: '',
        region: '',
        range: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      }
    }
  },
  computed: {
    ...mapGetters(['pickerOptions']) // 映射vuex中的getters
  },
  methods: {
    showCurrent(step) {
      return this.active === step
    },
    prev() {
      if (this.active >= 1) this.active--
    },
    next() {
      if (this.active < 2) this.active++
    },
    onSubmit() {
      this.active++
      this.loading = true
      setTimeout(() => {
        this.loading = false
        this.$message({
          type: 'success',
          message: '恭喜你，表单提交成功!'
        })
        this.active = 0
      }, 2000)
    }
  }
}
</script>
